﻿namespace DCHealthCheck {

    #region Usings
    using DCHealthCheck.DomainModel;
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Management;
    using System.Text;
    #endregion

    public class RoleFeatureBuilder {

        #region Members
        private readonly ManagementObject WmiObject;

        private readonly RoleFeature RoleFeature;
        #endregion

        #region Constructors
        private RoleFeatureBuilder() {
        }

        public RoleFeatureBuilder(RoleFeature roleFeature, ManagementObject wmiObject)
            : this() {
            if (roleFeature == null) {
                throw new ArgumentNullException("roleFeature");
            }
            if (wmiObject == null) {
                throw new ArgumentNullException("wmiObject");
            }

            this.RoleFeature = roleFeature;
            this.WmiObject = wmiObject;
        }
        #endregion

        #region Methods
        public RoleFeature GetInstance() {

            if (this.WmiObject["ID"] != null) {
                int id = 0;
                int.TryParse(this.WmiObject["ID"].ToString(), out id);
                this.RoleFeature.FeatureId = id;
            }
            if (this.WmiObject["Name"] != null) {
                this.RoleFeature.Name = this.WmiObject["Name"].ToString().Trim();
            }
            if (this.WmiObject["ParentID"] != null) {
                int id = 0;
                int.TryParse(this.WmiObject["ParentID"].ToString(), out id);
                this.RoleFeature.ParentFeatureId = id;
            }

            return this.RoleFeature;
        }
        #endregion

    }
}